package com.omt.tarjimdinek.domain.tv.entity;

import static javax.persistence.FetchType.LAZY;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.validation.constraints.Size;

import org.apache.log4j.Logger;
import org.hibernate.validator.constraints.NotEmpty;

import com.google.common.base.Objects;
import com.omt.tarjimdinek.domain.islamicLibrary.entity.Fatwa;
import com.omt.tarjimdinek.domain.islamicLibrary.entity.Sahabi;
import com.omt.tarjimdinek.domain.member.entity.Pays;
import com.omt.tarjimdinek.support.Identifiable;

/**
 * cheikh of islam
 * @author chabane
 *
 */
@Entity
@Table(name="a01_chk")
public class Cheikh implements Identifiable<Long>, Serializable{
	
    private static final long serialVersionUID = 1L;
    private static final Logger log = Logger.getLogger(Cheikh.class);
    
    /** ID SGBD */
	@Column(name="CNCHK", length=11)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	
    @Column(name = "VERSION", precision = 10)
    @Version
    private Integer version;
    
    /** Country of cheikh */
	@JoinColumn(name = "CNPYS", nullable = false)
	@ManyToOne(fetch = LAZY)
	private Pays pays;
	
	/** firstName of author */
    @Size(max = 45)
    @NotEmpty
	@Column(name="LIINTV1", nullable=false, length=45)
	private String nom;
	
	/** lastName of author */
    @Size(max = 45)
	@Column(name="LIINTV2", length=45)
	private String prenom;
    
	/** List of cheikh fatawas */
	@OneToMany(fetch = LAZY, mappedBy="cheikh")
	private List<Fatwa> listeFatwas;

	/**
	 * @return the pays
	 */
	public Pays getPays() {
		return pays;
	}

	/**
	 * @param pays the pays to set
	 */
	public void setPays(Pays pays) {
		this.pays = pays;
	}

	/**
	 * @return the listeFatwas
	 */
	public List<Fatwa> getListeFatwas() {
		return listeFatwas;
	}

	/**
	 * @param listeFatwas the listeFatwas to set
	 */
	public void setListeFatwas(List<Fatwa> listeFatwas) {
		this.listeFatwas = listeFatwas;
	}
	
	/**
     * equals implementation using a business key.
     */
    public boolean equals(Object other) {
        return this == other || (other instanceof Sahabi && hashCode() == other.hashCode());
    }
    
    /**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the nom
	 */
	public String getNom() {
		return nom;
	}

	/**
	 * @param nom the nom to set
	 */
	public void setNom(String nom) {
		this.nom = nom;
	}

	/**
	 * @return the prenom
	 */
	public String getPrenom() {
		return prenom;
	}

	/**
	 * @param prenom the prenom to set
	 */
	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}

	public int hashCode() {
        int hashCode = Objects.hashCode(getPrenom());
        return hashCode;
    }
	
    /**
	 * @return the version
	 */
	public Integer getVersion() {
		return version;
	}

	/**
	 * @param version the version to set
	 */
	public void setVersion(Integer version) {
		this.version = version;
	}

	/**
     * Set the default values.
     */
    public void initDefaultValues() {
    }
    
	@Transient
	public boolean isIdSet() {
	    return id != null && id.compareTo(Long.valueOf(0)) != 0;
	}
    
    /**
     * Construct a readable string representation for this Account instance.
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return Objects.toStringHelper(this) //
                .add("id", getId()) //
                .add("nom", getNom()) //
                .add("prenom", getPrenom()) //
                .add("pays", getPays()) //
                .add("version", getVersion()) //
                .toString();
    }
}
